﻿<!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                READ
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            document.addEventListener("deviceready", onDeviceReady, false);

            // device APIs are available
            //
            function onDeviceReady() {
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
            }

            function gotFS(fileSystem) {
                fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
            }

            function gotFileEntry(fileEntry) {
                fileEntry.file(gotFile, fail);
            }

            function gotFile(file) {
                readDataUrl(file);
                readAsText(file);
            }

            function readDataUrl(file) {
                var reader = new FileReader();
                reader.onloadend = function (evt) {
                    console.log("Read as data URL");
                    console.log(evt.target.result);
                };
                reader.readAsDataURL(file);
            }

            function readAsText(file) {
                var reader = new FileReader();
                reader.onloadend = function (evt) {
                    console.log("Read as text");
                    console.log(evt.target.result);
                    alert(evt.target.result);
                };
                reader.readAsText(file);
            }

            function fail(error) {
                console.log(error.code);
            }

        </script>
    </body>
</html>
